import { GET, POST, PUT, DELETE } from '../libs/request.js'
import { getAPIDomain } from '../libs/utils.js'

export const API_wxLogin = (data) => {
  const url = `${getAPIDomain()}/v1/auth/wxLogin`
  return POST(url, data)
}

export const API_wxUploadFile = (filePath, callback) => {
  const userId = wx.getStorageSync('userId')
  wx.uploadFile({
    url: `${getAPIDomain()}/v1/users/${userId}/avatar`,
    filePath: filePath,
    name: 'file',
    header: {
      authorization: wx.getStorageSync('authorization')
    },
    success: callback
  })
}

export const API_getUserInfo = () => {
  const userId = wx.getStorageSync('userId')
  const url = `${getAPIDomain()}/v1/users/${userId}`
  return GET(url)
}

export const API_changeUserInfo = (data) => {
  const userId = wx.getStorageSync('userId')
  const url = `${getAPIDomain()}/v1/users/${userId}`
  return PUT(url, data)
}
